<?php

class User_Form_UserProfile extends Custom_Form
{

	private $_user_id = '';

	function  __construct($user_id = '') {
		$this->_user_id = $user_id;
		parent::__construct(null);
	}

	public function init()
    {
		$translate = Zend_Registry::get('translate');
		$config = Zend_Registry::get('config');
		$this->setTranslator($translate);
	    $this->setName("signup");
        $this->setMethod('post');
		

		$this->addElement('text', 'first_name', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 50)),
				array('Alnum'),
			),

            'required'   => true,
            'label'      => __('First Name').':',
        ));

		$this->addElement('text', 'last_name', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 50)),
				array('Alnum'),
            ),
            'required'   => true,
            'label'      => __('Last Name').':',
        ));

        $this->addElement('textarea', 'address', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 255)),
		    ),
            'required'   => true,
            'rows'       => 3,
            'cols'       => 50,
            'label'      => __('Address').':',
        ));

        $this->addElement('text', 'email', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('StringLength', false, array(0, 75)),
				array('EmailAddress'),
				array('Db_NoRecordExists',false,array('table'=>'vt_users','field'=>'email','exclude'=>array('field'=>'id','value'=>$this->_user_id)))
            ),
            'required'   => true,
            'label'      => __('Email').':',
        ));

        //user form validation message
		$this->addElement('file', 'image', array(
            'label'      => __('Select Image').':',
			'decorators' => $this->setCustomFileDecorators(),
		));

        $config   = Zend_Registry::get('config');
        $filePath = PUBLIC_PATH. DS .$config->params->user->imagePath;
        $size     = $config->params->upload->imageSize * 1024 * 1024;
        
        $this->image->setDestination($filePath);
        $this->image->addValidator('Size', false, $size);
        $this->image->addValidator('Extension', false, 'jpg,png,gif');
    
		$this->addElement('submit', 'save', array(
            'required' => false,
            'ignore'   => true,
            'label'    => __('Save'),
        ));
		$this->save->removeDecorator('label');
		
	}
}